<template>
  <div class="herder">
    <div class="herder_top">
      <!-- 头部 -->
      <div class="headerLeft" style="cursor: pointer;" @click="goBack">
        <!-- <img style="width:24px;height:24px" src="@/assets/imgs/Slice 12@2x.png" alt=""> -->
        <div style="margin-left:4px">
          X in 1自动检测设备
        </div>
      </div>
      <div class="headerLeft">
        <div style="margin-right:40px">
          <i class="el-icon-setting" />
        </div>
        <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
            <span>{{ userName }}</span>
            <i class="el-icon-caret-bottom" />
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item divided @click.native="logout">
              <span>退出登录</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div class="herder_bottom">
      <div class="runningTime">
        <div class="runningTime_Tip">
          系统投入运行时间：
        </div>
        <div class="time">
          2022/06/23 ~ {{ time }}
        </div>
      </div>
      <div class="runningTime">
        <div class="runningTime_Tip">
          当前时间：
        </div>
        <div class="time">
          {{ time }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { removeToken } from '@/utils/auth'
export default {
  props: {
    isBack: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  data() {
    return {
      time: '',
      userName: ''
    }
  },
  mounted() {
    this.userName = localStorage.getItem('userName')
    this.time = this.addDate()
  },
  methods: {
    addDate() {
      const nowDate = new Date(),
        date = {
          year: nowDate.getFullYear(),
          month: nowDate.getMonth() + 1,
          date: nowDate.getDate()
        },
        newmonth = date.month > 10 ? date.month : '0' + date.month,
        day = date.date > 10 ? date.date : '0' + date.date,
        time = date.year + '/' + newmonth + '/' + day
      return time
    },
    goBack() {
      this.$router.push('/home')
    },
    logout() {
      removeToken()
      this.$router.push('/login')
    }
  }
}
</script>

<style  lang="scss" scoped>
.herder_top{
  width: calc(100% - 48px);
  min-width: 1550px;
  height: 56px;
  background: #1EBAB2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
}
.headerLeft{
  display: flex;
  align-items: center;
  font-size: 18px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #FFFFFF;
}
.herder_bottom{
  width: calc(100% - 48px);
  min-width: 1550px;
  padding: 0 24px;
  height: 44px;
  background-color: #FFFFFF;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.runningTime{
  display: flex;
  align-items: center;
  .runningTime_Tip{
    font-size: 14px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #8C8C8C;
  }
  .time{
    font-size: 14px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
  }
}
.avatar-wrapper{
  cursor: pointer;
  color: #FFFFFF;
}
.right-menu {
  float: right;
  height: 100%;
  line-height: 50px;

  &:focus {
    outline: none;
  }

  .right-menu-item {
    display: inline-block;
    padding: 0 8px;
    height: 100%;
    font-size: 18px;
    color: #5a5e66;
    vertical-align: text-bottom;

    &.hover-effect {
      cursor: pointer;
      transition: background .3s;

      &:hover {
        background: rgba(0, 0, 0, .025)
      }
    }
  }

  .avatar-container {
    margin-right: 30px;

    .avatar-wrapper {
      margin-top: 5px;
      position: relative;

      .user-avatar {
        cursor: pointer;
        width: 40px;
        height: 40px;
        border-radius: 10px;
      }

      .el-icon-caret-bottom {
        cursor: pointer;
        position: absolute;
        right: -20px;
        top: 25px;
        font-size: 12px;
      }
    }
  }
}
</style>
